import {post, get, message} from '@/utils/utils'

const setPassword = {
  namespaced: true,
  state: {
    hasSetPayPassword: true
  },

  mutations: {
    save(state, { field, payload }) {
      if (Object.prototype.toString.call(payload) === '[object Object]') {
        state[field] = { ...state[field], ...payload }
      } else {
        state[field] = payload
      }
    }
  },

  actions: {
    getPasswordStatus({ commit }) {
      get({
        api: '/agt/agentinfoPaymentWord/checkSetPaymentpassword',
        noTip: true,
        success: ({data}) => {
          commit('save', {field: 'hasSetPayPassword', payload: data})
        },
        fail: ({code}) => {
          if (code === 0) commit('save', {field: 'hasSetPayPassword', payload: false})
        }
      })
    },

    checkOriginalPassword({ commit }, oldPaymentpassword) {
      return get({
        api: `/agt/agentinfoPaymentWord/checkOldPaymentword/${oldPaymentpassword}`,
        success: ({data}) => {
        }
      })
    },

    setPassword({ commit }, payload) {
      return post({api: '/agt/agentinfoPaymentWord/setPaymentPassword',
        data: payload
      })
    }
  }
}

export default setPassword
